#ifndef SROS_CONTROL_CHASSIS_HPP
#define SROS_CONTROL_CHASSIS_HPP

#include <core/node.hpp>
#include <core/core.hpp>
#include <commons/util/util.hpp>
#include <commons/config/config.hpp>

#include <mutex>
#include <atomic>

#include "support-chassis/support_proto.hpp"

namespace sros::plugins
{
    class Mqtt;
}

namespace sros::async
{
    class Timer;
}

namespace sros::net
{
    class HttpServer;
}

namespace sros::control
{

class Cfg;
class chassisNode : public Node
{
public:
    enum : uint8_t
    {
        H = 0,
        V = 1
    };

    chassisNode(const std::string &name = "chassis", const std::string &module = "control");
    ~chassisNode() = default;
    
    RetBool init() override;
    
    void run() override;
    
    void close() override;
    
private:
    // 位置环
    void position_loop_();

    // 速度环
    void speed_loop_();

private:
    std::shared_ptr<commons::Config<Cfg>> cfg_;
    std::shared_ptr<async::Timer> timer_;
    std::shared_ptr<plugins::Mqtt> mqtt_;
    std::shared_ptr<net::HttpServer> http_server_;

    std::mutex mtx_;
    std::vector<EncoderStatus> encoder_list_;
    std::atomic<int32_t> target_spd_;
};


}

#endif

